'''
@Project ：my_python_project 
@File    ：_subprocess.py
@IDE     ：PyCharm 
@Author  ：xionglinhui
@Date    ：2024/9/23 下午4:17 
'''

import subprocess

obj = subprocess.Popen('cat 123.txt', shell=True,
                       stdout=subprocess.PIPE,
                       stderr=subprocess.PIPE
                       )

print(obj)
res = obj.stdout.read()
print(res.decode('utf-8'))


obj2 = subprocess.Popen('cat 1234.txt', shell=True,
                       stdout=subprocess.PIPE,
                       stderr=subprocess.PIPE
                       )


err_res = obj2.stderr.read()
print(f'obj2.stderr的结果为：{err_res.decode("utf-8")}')
# obj2.stderr的结果为：cat: 1234.txt: 没有那个文件或目录